﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TransCode.Entitys;
using TransCode.Player.EntityViews;

namespace TransCode.Player.ImagePage
{
    /// <summary>
    /// Interaction logic for TargetImageItem.xaml
    /// </summary>
    public partial class TargetImageItem : UserControl
    {
        static DependencyProperty VideoSourceProperty;

        public TargetImageItem()
        {
            InitializeComponent();
        }

        static TargetImageItem()
        {
            VideoSourceProperty = DependencyProperty.Register(
                "VideoSource", typeof(Video), typeof(TargetImageItem),
                new PropertyMetadata(null,
                    (DependencyObject d, DependencyPropertyChangedEventArgs e) =>
                    {
                        TargetImageItem ui = d as TargetImageItem;
                        Video video = e.NewValue as Video;
                        ui.title.Text = video.VideoName;
                        ui.targetList.ItemsSource = video.TargetList.Select(it => { return new TargetView() { Video = video, Target = it }; });
                    }));
        }

        public Video VideoSource
        {
            get { return GetValue(TargetImageItem.VideoSourceProperty) as Video; }
            set { SetValue(TargetImageItem.VideoSourceProperty, value); }
        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Common.VideoMainPage.Play(VideoSource);
            Common.Change(FuncEnum.Video);
        }

        private void targetList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {

                TargetView tView = e.AddedItems[0] as TargetView;
                ImageBoxControl imagebox = new ImageBoxControl();
                imagebox.TargetSource = tView.Target.ObjectList;
                Grid.SetColumnSpan(imagebox, 2);

                Common.ImageMainPage.ShowImageBox(imagebox);

                (sender as ListBox).SelectedIndex = -1;
            }
        }
    }
}
